import { View } from "../../../mvc/core/View";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { FilterConst } from "../../../component/gconst/FilterConst";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { SGangFightsInvitePlayer } from "../../../../Message/Public/SGangFightsInvitePlayer";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { GangFightsInviteWindow } from "./GangFightsInviteWindow";
import { EffectManager } from "../../manager/EffectManager";
import { UIIconEvent } from "../uiIconBtn/UIIconEvent";
import { DataEvent } from "../../events/DataEvent";
//class GangFightsInviteTeamIcon
    
    export  class GangFightsInviteTeamIcon extends View
    {
        constructor()
        {
            super();
            this.buttonMode = true;
            this._aryRequest = new Array<any>();
            this.initView();
            this.addListeners();
            return;
        }

        public set labelTxt(arg1: string)
        {
            this._labelTxt.text = arg1;
            this.textFormat = new GTextFormat(FontUtil.songtiName, 10, 16777215);
            this._labelTxt.setTextFormat(this.textFormat);
            return;
        }

        /* internal  */initView(): void
        {
            var loc1=GlobalClass.getBitmap(ImagesConst.GangFightsHintIcon);
            this.addChild(loc1);
            this._labelTxt = new Object /* flash.text.TextField */();
            this._labelTxt.selectable = false;
            this._labelTxt.filters = [FilterConst.glowFilter];
            this._labelTxt.width = loc1.width;
            this._labelTxt.height = 10;
            this._labelTxt.autoSize = flash.text.TextFieldAutoSize.RIGHT;
            this._labelTxt.y = loc1.height - 14;
            addChild(this._labelTxt);
            return;
        }

        /* internal  */addListeners(): void
        {
            this.addEventListener(flash.events.MouseEvent.CLICK, this.showReplyWindow);
            Dispatcher.addEventListener(EventName.GangFightsDelInviteRequest, this.onGangFightsDelRequestHandler);
            Dispatcher.addEventListener(EventName.GangFightsDelAllInviteRequest, this.onGangFightsDelAllInviteRequestHandler);
            return;
        }

        public showIcon(arg1: SGangFightsInvitePlayer): void
        {
            var loc2=null;
            var loc1=new PlayerMiniInfo(arg1.fromMiniPlayer);
            var loc3=0;
            var loc4=this._aryRequest;
            for(loc2 of loc4) 
            {
                if (EntityUtil.toString(loc2.fromMiniPlayer.entityId) != EntityUtil.toString(arg1.fromMiniPlayer.entityId)) 
                {
                    continue;
                }
                return;
            }
            this._aryRequest.push(arg1);
            this.labelTxt = String(this._aryRequest.length);
            this.show();
            return;
        }

        /* internal  */showReplyWindow(arg1: Object /* flash.events.MouseEvent */=null): void
        {
            this.labelTxt = String(this._aryRequest.length);
            if (this._teamInviteWindow == null) 
            {
                this._teamInviteWindow = new GangFightsInviteWindow();
            }
            if (this._aryRequest.length > 0) 
            {
                this._teamInviteWindow.updateDataProvider(this._aryRequest);
                this._teamInviteWindow.show();
            }
            else 
            {
                if (this.parent) 
                {
                    this.parent.removeChild(this);
                    EffectManager.glowFilterUnReg(this);
                    this.dispatchEvent(new UIIconEvent(UIIconEvent.RemoveIcon));
                }
                this._teamInviteWindow.hide();
            }
            return;
        }

        /* internal  */onGangFightsDelRequestHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as SGangFightsInvitePlayer;
            var loc2=this._aryRequest.indexOf(loc1);
            this._aryRequest.splice(loc2, 1);
            this.showReplyWindow(null);
            return;
        }

        /* internal  */onGangFightsDelAllInviteRequestHandler(arg1: DataEvent): void
        {
            this._aryRequest = [];
            this.showReplyWindow(null);
            return;
        }

        public static get instance(): GangFightsInviteTeamIcon
        {
            if (!GangFightsInviteTeamIcon._instance) 
            {
                GangFightsInviteTeamIcon._instance = new GangFightsInviteTeamIcon();
            }
            return GangFightsInviteTeamIcon._instance;
        }

        /* internal */ /* var */_aryRequest: Array<any>;

        /* internal */ /* var */_labelTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */textFormat: Object /* flash.text.TextFormat */;

        /* internal */ /* var */_teamInviteWindow: GangFightsInviteWindow;

        /* internal */ static /* var */_instance: GangFightsInviteTeamIcon;
    }
